package com.haitaoit.chengquan.module.center.activity.info;

import android.content.Intent;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
import android.view.View;
import android.widget.TextView;

import com.haitaoit.chengquan.R;
import com.haitaoit.chengquan.base.BaseActivity;
import com.haitaoit.chengquan.module.center.model.UserInfoModel;
import com.haitaoit.chengquan.utils.ToastUtils;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;

public class MyMoneyActivity extends BaseActivity {
    @ViewInject(R.id.money_num)
    TextView money_num;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView_V(R.layout.activity_my_money);
        setTitle_V("我的钱包");
        setLeftShow(1, R.mipmap.left);
        setRightShow(0, R.string.detail);
        backLeft_V();
        ViewUtils.inject(this);


        // 部分字体变大变色
        SpannableString msp = new SpannableString(UserInfoModel.getUser_info().getBalance() + " 元");
        msp.setSpan(new RelativeSizeSpan(2f), 0, UserInfoModel.getUser_info().getBalance().length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        msp.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, UserInfoModel.getUser_info().getBalance().length(),
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // 粗体
//        money_num.setText(msp);
        money_num.setText(UserInfoModel.getUser_info().getBalance() + " 元");
    }

    @OnClick({R.id.right, R.id.money_tixian})
    public void onClick(View v) {
        super.onClick(v);
        Intent intent = new Intent();
        switch (v.getId()) {
            case R.id.right:
                intent.setClass(MyMoneyActivity.this, MyMoneyDetailActivity.class);
                startActivity(intent);
                break;
            case R.id.money_tixian:
                intent.setClass(MyMoneyActivity.this, MyMoneyTixianActivity.class);
                startActivityForResult(intent,100);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode==100&&resultCode==101){
            double money = data.getDoubleExtra("money", 0);
            String string = UserInfoModel.getUser_info().getBalance();
            if(!TextUtils.isEmpty(string)){
                double v = Double.parseDouble(string) - money;
                money_num.setText(v+"");
            }
        }
    }
}
